package com.aaa.dem1107.d02;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/11/7  15:54
 */
public class Test {
    public static void main(String[] args) {
        /**
         * 日期
         */
        LocalDate date = LocalDate.of(2020, 11, 1);
        LocalDate now = LocalDate.now();
        //比较两个日期的距离
        Period period = Period.between(date, now);
        System.out.println("相差的年:"+ period.getYears());
        System.out.println("相差的月:"+ period.getMonths());
        System.out.println("相差的天:"+ period.getDays());

        /**
         * 时间
         */
        LocalTime time = LocalTime.of(15, 56, 12);
        LocalTime now1 = LocalTime.now();
        Duration between = Duration.between(time, now1);
        System.out.println(between.toHours());
        System.out.println(between.toMinutes()); //时间与时间之间相差的分钟
        System.out.println(between.getSeconds());//时间与时间之间相差的秒


    }
}
